package com.cyh.pangu.offer;

import com.cyh.pangu.offer.common.ListNode;
import com.cyh.pangu.offer.common.ListUtils;

public class Offer24 {

    public ListNode reverseList(ListNode head) {

        ListNode newHead = null;
        while (head != null) {
            ListNode tempNode = head.next;
            head.next = newHead;
            newHead = head;
            head = tempNode;
        }
        return newHead;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5};
        ListNode buildList = ListUtils.buildList(nums);
        ListNode head = buildList;
        Offer24 offer24 = new Offer24();
        ListNode result = offer24.reverseList(head);
        ListUtils.printList(result);
    }


}
